package com.sixtwo.order.controller;

import com.alibaba.fastjson.JSON;
import com.sixtwo.dto.CommonResult;
import com.sixtwo.order.dto.CreateOrderDto;
import com.sixtwo.order.vo.OrderDetailVo;
import com.sixtwo.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope;

@Slf4j
@RestController
@RequestScope
public class OrderController {

    @Value("${useLocalCache:false}")
    private boolean useLocalCache;

    @RequestMapping("/get")
    public boolean get() {
        return useLocalCache;
    }

    @Autowired
    private OrderService orderService;

    @PostMapping("/order/createOrder")
    public CommonResult<OrderDetailVo> createOrder(@RequestBody @Validated CreateOrderDto createOrderDto) {
        log.info("创建订单请求参数: {}", JSON.toJSONString(orderService));
        return orderService.createOrder(createOrderDto);
    }
}
